const path = require('path')
const Webpack = require('webpack')
const HtmlPlugin=require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const mode = process.argv[2].split("=")[1]
const babelLoader = {
                        loader: 'babel-loader',
                        options: {
                            presets: [[
                                '@babel/preset-env',//管你是2015还是2015，包含所有的ES版本
                                {
                                    "modules": false,
                                    "useBuiltIns": "usage",//polyfill按需引入
                                    "corejs": 2//使用了useBuiltIns必须指定@babel/runtime版本
                                }
                            ]],
                            // plugins: ['@babel/plugin-transform-runtime']
                        }
                    }

module.exports = {
   
    // 入口：表示要使用webpack打包哪个文件
    entry: {
        bundle:path.join(__dirname, './main.js'),
        // worker:path.join(__dirname, './script/webworker/worker.js')
    },
    // 出口：输出文件的相关配置
    output: {
        // 指定打包好的文件，输出到哪个目录中去
        path: path.join(__dirname, './webpaint/dist'),
        // 指定输出的文件名称
        filename: '[name].js'
    },
    module:{
        rules:[

             {
                test: /\.js$/,
                exclude: /node_modules/,
                use: [
                    babelLoader
                ]
            },
            {
                test:/\.jcss$/,
                use:[path.resolve(__dirname, './loaders/text-loader.js')]
            },
            {
                test:/\.tpl\.html$/,
                use:[path.resolve(__dirname, './loaders/text-loader.js')]
            },
            {
                test:/\.plugin\.js$/,
                use:[
                babelLoader,
                path.resolve(__dirname, './loaders/plugin-loader.js')]
            },
            {
                test:/\.action\.js$/,
                use:[
                babelLoader,
                path.resolve(__dirname, './loaders/action-loader.js')]
            },
             {
                test:/\.shape\.js$/,
                use:[
                babelLoader,
                path.resolve(__dirname, './loaders/shape-loader.js')]
            },
            {
                test:/\.css$/,
                // webpack的loader执行顺序是反的,先执行css-loader后执行style-loader
                use:[
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.(png|svg)$/,
                use: [
                    'file-loader'
                    ]
            },
            {
                test: /\.(eot|ttf|woff|woff2)$/,
                use: [
                   'file-loader'
                    ]
           }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlPlugin({template:"./template.html",title:"Geo"}),
        new Webpack.DefinePlugin({
            __GEO_: JSON.stringify(mode),
        })
    ],
    mode,
    devtool: 'source-map'
}